﻿@using Microsoft.AspNetCore.Components.Rendering
@inherits LayoutComponentBase
@inject GlobalConfig GlobalConfig
@implements IDisposable

<MApp>
    <MAppBar Elevation=0 App MaxHeight=60 Class="@($"{(GlobalConfig.PageMode == PageModes.PageTab ?"mx-6":"mx-6 rounded-b-4")}")">
        <Favorite />
        <MSpacer />
        <Search />
        <MIcon Size=20 Class="ml-5" Color="neutral-lighten-3">mdi-message-processing-outline</MIcon>
        <MIcon Size=20 Class="ml-5" Color="neutral-lighten-3" OnClick="()=> _showSetting = true">mdi-cog</MIcon>
        <Language />
        <Login />
    </MAppBar>

    <Navigation />

    <MMain Class="fill-lighten-1" Style="padding-top:60px">
        @if (GlobalConfig.PageMode == PageModes.Breadcrumb)
        {
            <div class="pa-6 max-width">
                <Breadcrumb></Breadcrumb>
                @Body
            </div>
        }
        else if (GlobalConfig.PageMode == PageModes.PageTab)
        {
            <PageTabs>
                @Body
            </PageTabs>
        }
        else
        {
            <div class="pa-6 max-width">
                @Body
            </div>
        }
    </MMain>

    <Settings @bind-Show=_showSetting />
</MApp>

@code {

    private bool _showSetting;

    protected override void OnInitialized()
    {
        GlobalConfig.OnPageModeChanged += base.StateHasChanged;
    }

    public void Dispose()
    {
        GlobalConfig.OnPageModeChanged -= base.StateHasChanged;
    }
}